#ifndef _UART_H_
#define _UART_H_

/*
 * OMAP L138 UART configuration
*/

#include "types.h"
#include "board_config.h"

#define UART_0	0x01C42000
#define UART_1	0x01D0C000
#define UART_2	0x01D0D000

#if (UART_IN_USE == 0)
#define UART_BASE UART_0
#elif (UART_IN_USE == 1)
#define UART_BASE UART_1
#else
#define UART_BASE UART_2
#endif

#define UART_RBR	*((volatile uint32_t *)(UART_BASE + 0x0))		// Receive buffer register
#define UART_THR	*((volatile uint32_t *)(UART_BASE + 0x0))		//Transmitter holding register
#define UART_IER	*((volatile uint32_t *)(UART_BASE + 0x4))		// Interrupt enable register
#define UART_IIR	*((volatile uint32_t *)(UART_BASE + 0x8))		// Interrupt identification register
#define UART_FCR	*((volatile uint32_t *)(UART_BASE + 0x8))		// FIFO Control register (write only)
#define UART_LCR	*((volatile uint32_t *)(UART_BASE + 0xC))		// Line control register
#define UART_MCR	*((volatile uint32_t *)(UART_BASE + 0x10))		// Modem control register
#define UART_LSR	*((volatile uint32_t *)(UART_BASE + 0x14))		// Line status register
#define UART_MSR	*((volatile uint32_t *)(UART_BASE + 0x18))		// Modem status register
#define UART_SCR	*((volatile uint32_t *)(UART_BASE + 0x1c))		// Scratchpad register
#define UART_DLL	*((volatile uint32_t *)(UART_BASE + 0x20))		// Divisor LSB latch
#define UART_DLH	*((volatile uint32_t *)(UART_BASE + 0x24))		// Divisor MSB latch
#define UART_REVID	*((volatile uint32_t *)(UART_BASE + 0x28))		// Revision identification register
#define UART_PEMR	*((volatile uint32_t *)(UART_BASE + 0x30))		// Power and emulation management register
#define UART_MDR	*((volatile uint32_t *)(UART_BASE + 0x34))		// Mode definition register

void uart_init(void);


static inline void uart_put(uint8_t data)
{

	while ((UART_LSR & 0x20) == 0);
	
	if (data == '\n') {
		UART_THR = '\r';
		while ((UART_LSR & 0x20) == 0);
	}

	UART_THR = data;
	return;
}

void uart_print(uint8_t *str);
#endif

